/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * vista.java
 *
 * Created on 24-oct-2009, 18:41:52
 */

import java.util.ArrayList;

/**
 *
 * @author Administrador
 */
public class vistaa extends javax.swing.JFrame {

    int varios = 0;
    ArrayList al;
    dialogg dia;
    operaciones op;
    /** Creates new form vista */
    public vistaa() {
              

        initComponents();
       
  op = new operaciones(this);
  dia = new dialogg(this, true);
    }
    public void bajadoo (String a){
    bajado.setText(a);
}


    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        jPanel3 = new javax.swing.JPanel();
        sistema = new javax.swing.JLabel();
        jButton3 = new javax.swing.JButton();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel1 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTextArea1 = new javax.swing.JTextArea();
        jButton1 = new javax.swing.JButton();
        jLabel4 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        jButton2 = new javax.swing.JButton();
        serie = new javax.swing.JTextField();
        ini = new javax.swing.JTextField();
        fin = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        bajado = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jPanel3.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        sistema.setForeground(new java.awt.Color(255, 0, 51));
        sistema.setText("PIWIPIIIII");
        jPanel3.add(sistema, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 310, 120, 20));

        jButton3.setText(":-)");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });
        jPanel3.add(jButton3, new org.netbeans.lib.awtextra.AbsoluteConstraints(240, 310, -1, -1));

        jTextArea1.setColumns(20);
        jTextArea1.setRows(5);
        jScrollPane2.setViewportView(jTextArea1);

        jButton1.setText("bajar");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jLabel4.setText("Lista de Links:");

        org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel1Layout.createSequentialGroup()
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jPanel1Layout.createSequentialGroup()
                        .add(30, 30, 30)
                        .add(jLabel4))
                    .add(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .add(jScrollPane2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 242, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .add(jPanel1Layout.createSequentialGroup()
                        .add(113, 113, 113)
                        .add(jButton1)))
                .addContainerGap(63, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel1Layout.createSequentialGroup()
                .add(5, 5, 5)
                .add(jLabel4)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jScrollPane2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 119, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(36, 36, 36)
                .add(jButton1)
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Los eliges tu", jPanel1);

        jButton2.setText("Bajar");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jLabel1.setText("Desde");

        jLabel2.setText("AL");

        jLabel3.setText("Manga a descargar");

        jLabel5.setForeground(new java.awt.Color(255, 0, 0));
        jLabel5.setText("NO FUNCIONA ESTE APARTADO");

        org.jdesktop.layout.GroupLayout jPanel2Layout = new org.jdesktop.layout.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jPanel2Layout.createSequentialGroup()
                        .add(serie, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 295, Short.MAX_VALUE)
                        .addContainerGap())
                    .add(jPanel2Layout.createSequentialGroup()
                        .add(jLabel3)
                        .addContainerGap(213, Short.MAX_VALUE))
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel2Layout.createSequentialGroup()
                        .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                            .add(jButton2)
                            .add(org.jdesktop.layout.GroupLayout.LEADING, jPanel2Layout.createSequentialGroup()
                                .add(jLabel1)
                                .add(18, 18, 18)
                                .add(ini, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 51, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 110, Short.MAX_VALUE)
                                .add(jLabel2)))
                        .add(18, 18, 18)
                        .add(fin, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 45, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .add(21, 21, 21))))
            .add(jPanel2Layout.createSequentialGroup()
                .add(20, 20, 20)
                .add(jLabel5, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 223, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(72, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel2Layout.createSequentialGroup()
                .add(15, 15, 15)
                .add(jLabel3)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(serie, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(18, 18, 18)
                .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel1)
                    .add(ini, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(fin, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabel2))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 33, Short.MAX_VALUE)
                .add(jLabel5)
                .add(18, 18, 18)
                .add(jButton2)
                .add(31, 31, 31))
        );

        jTabbedPane1.addTab("Serie", jPanel2);

        jPanel3.add(jTabbedPane1, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 10, 320, 240));

        bajado.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bajadoActionPerformed(evt);
            }
        });
        jPanel3.add(bajado, new org.netbeans.lib.awtextra.AbsoluteConstraints(40, 270, 242, -1));

        getContentPane().add(jPanel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 340, 340));

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed

        al = new ArrayList();
        String c = "", c1 = "", c2 = "http";
        c = jTextArea1.getText();
        try {
            int i = 0;
            while (c.length() > 0) {
                i = c.lastIndexOf("http");
                c1 = c.substring(i);
                c = c.substring(0, i);
                //  System.out.println("I    "+i);
                //   System.out.println("c1 "+c1);
                //  System.out.println("c "+c);
                //   System.out.println("longitud "+c.length());
                al.add(c1);
                c1 = "";
            }
            // al.add(c);
        } catch (Exception e) {
        }
        //    al.add(c);
        varios();

        // TODO add your handling code here:
}//GEN-LAST:event_jButton1ActionPerformed


    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed

        //http://submanga.com/Gantz/306/50111

        int i;
        int f;
        try{

            i =Integer.parseInt(""+ini.getText());
            f =Integer.parseInt(""+fin.getText());
            while(i<=f){

                sistema.setText("bajando "+serie.getText()+" "+i);
                System.out.println("ddd");
                op.bajaruno("http://submanga.com/"+serie.getText().trim()+"/"+i+"");
                i++;

            }

        }catch(Exception e){
            sistema.setText("ERROR EN LOS DATOS");

        }


        // TODO add your handling code here:
}//GEN-LAST:event_jButton2ActionPerformed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed

dia.setVisible(true);


        // TODO add your handling code here:
    }//GEN-LAST:event_jButton3ActionPerformed

    private void bajadoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bajadoActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_bajadoActionPerformed

  

    private void varios() {
        System.out.println("" + al.size());
      
        if (al.size() == 1) {

            bajado.setText("bajando el unico puesto");
             op.bajaruno("" + al.get(0));

        } else {
                     for (int i = 0; i <= al.size() - 1; i++) {

            bajado.setText("bajando el " + (i + 1));
                                  System.out.println(""+al.get(al.size() - 1 -i));
              op.bajaruno("" + al.get(al.size() - 1 -i));

            }
        }
        al.clear();
        jTextArea1.setText("");
        bajado.setText("ACABO:::::::::::::");
    }


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField bajado;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JTextField fin;
    private javax.swing.JTextField ini;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JTextArea jTextArea1;
    private javax.swing.JTextField serie;
    private javax.swing.JLabel sistema;
    // End of variables declaration//GEN-END:variables



   
}
